package araujoCoronelVillamayor.plantasVsZombies.appModelsArena;

import araujoCoronelVillamayor.plantasVsZombies.appModelsArena.SesionAppModel;
import araujoCoronelVillamayor.plantasVsZombies.domain.FactoryZombies;
import araujoCoronelVillamayor.plantasVsZombies.domain.Zombie;
import com.google.common.base.Objects;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.uqbar.commons.utils.Observable;

@Observable
@SuppressWarnings("all")
public class AlmanaqueAppModel {
  private FactoryZombies _factoryZombies;
  
  public FactoryZombies getFactoryZombies() {
    return this._factoryZombies;
  }
  
  public void setFactoryZombies(final FactoryZombies factoryZombies) {
    this._factoryZombies = factoryZombies;
  }
  
  private ArrayList<Zombie> _tiposZombies;
  
  public ArrayList<Zombie> getTiposZombies() {
    return this._tiposZombies;
  }
  
  public void setTiposZombies(final ArrayList<Zombie> tiposZombies) {
    this._tiposZombies = tiposZombies;
  }
  
  private SesionAppModel _sesionAppModel;
  
  public SesionAppModel getSesionAppModel() {
    return this._sesionAppModel;
  }
  
  public void setSesionAppModel(final SesionAppModel sesionAppModel) {
    this._sesionAppModel = sesionAppModel;
  }
  
  private String _zombieBuscado;
  
  public String getZombieBuscado() {
    return this._zombieBuscado;
  }
  
  public void setZombieBuscado(final String zombieBuscado) {
    this._zombieBuscado = zombieBuscado;
  }
  
  private List<Zombie> _resultadoBusqueda;
  
  public List<Zombie> getResultadoBusqueda() {
    return this._resultadoBusqueda;
  }
  
  public void setResultadoBusqueda(final List<Zombie> resultadoBusqueda) {
    this._resultadoBusqueda = resultadoBusqueda;
  }
  
  public AlmanaqueAppModel(final SesionAppModel sesionAppModelParametro) {
    this.setSesionAppModel(sesionAppModelParametro);
    ArrayList<Zombie> _arrayList = new ArrayList<Zombie>();
    this.setTiposZombies(_arrayList);
    FactoryZombies _instance = FactoryZombies.getInstance();
    this.setFactoryZombies(_instance);
    ArrayList<Zombie> _tiposZombies = this.getTiposZombies();
    FactoryZombies _factoryZombies = this.getFactoryZombies();
    Zombie _crearColinBlunstone = _factoryZombies.crearColinBlunstone();
    _tiposZombies.add(_crearColinBlunstone);
    ArrayList<Zombie> _tiposZombies_1 = this.getTiposZombies();
    FactoryZombies _factoryZombies_1 = this.getFactoryZombies();
    Zombie _crearColinBlunstone_1 = _factoryZombies_1.crearColinBlunstone();
    _tiposZombies_1.add(_crearColinBlunstone_1);
    ArrayList<Zombie> _tiposZombies_2 = this.getTiposZombies();
    FactoryZombies _factoryZombies_2 = this.getFactoryZombies();
    Zombie _crearColinBlunstone_2 = _factoryZombies_2.crearColinBlunstone();
    _tiposZombies_2.add(_crearColinBlunstone_2);
    ArrayList<Zombie> _tiposZombies_3 = this.getTiposZombies();
    FactoryZombies _factoryZombies_3 = this.getFactoryZombies();
    Zombie _crearColinBlunstone_3 = _factoryZombies_3.crearColinBlunstone();
    _tiposZombies_3.add(_crearColinBlunstone_3);
    ArrayList<Zombie> _tiposZombies_4 = this.getTiposZombies();
    FactoryZombies _factoryZombies_4 = this.getFactoryZombies();
    Zombie _crearCranberrie = _factoryZombies_4.crearCranberrie();
    _tiposZombies_4.add(_crearCranberrie);
    ArrayList<Zombie> _tiposZombies_5 = this.getTiposZombies();
    FactoryZombies _factoryZombies_5 = this.getFactoryZombies();
    Zombie _crearCranberrie_1 = _factoryZombies_5.crearCranberrie();
    _tiposZombies_5.add(_crearCranberrie_1);
    ArrayList<Zombie> _tiposZombies_6 = this.getTiposZombies();
    FactoryZombies _factoryZombies_6 = this.getFactoryZombies();
    Zombie _crearCranberrie_2 = _factoryZombies_6.crearCranberrie();
    _tiposZombies_6.add(_crearCranberrie_2);
    ArrayList<Zombie> _tiposZombies_7 = this.getTiposZombies();
    FactoryZombies _factoryZombies_7 = this.getFactoryZombies();
    Zombie _crearCranberrie_3 = _factoryZombies_7.crearCranberrie();
    _tiposZombies_7.add(_crearCranberrie_3);
  }
  
  public void buscar() {
    ArrayList<Zombie> _tiposZombies = this.getTiposZombies();
    final Function1<Zombie,Boolean> _function = new Function1<Zombie,Boolean>() {
      public Boolean apply(final Zombie Zombie) {
        String _zombieBuscado = AlmanaqueAppModel.this.getZombieBuscado();
        String _nombre = Zombie.getNombre();
        boolean _search = AlmanaqueAppModel.this.search(_zombieBuscado, _nombre);
        return Boolean.valueOf(_search);
      }
    };
    Iterable<Zombie> _filter = IterableExtensions.<Zombie>filter(_tiposZombies, _function);
    List<Zombie> _list = IterableExtensions.<Zombie>toList(_filter);
    this.setResultadoBusqueda(_list);
  }
  
  public void limpiar() {
    this.setZombieBuscado("");
    this.buscar();
  }
  
  /**
   * Busca los zombies que coincidan con los datos recibidos. Tanto ataque, defensa como nombre pueden ser nulos,
   * en ese caso no se filtra por ese atributo.
   */
  public boolean search(final Object expectedValue, final Object realValue) {
    boolean _xblockexpression = false;
    {
      boolean _equals = Objects.equal(expectedValue, null);
      if (_equals) {
        return true;
      }
      boolean _equals_1 = Objects.equal(realValue, null);
      if (_equals_1) {
        return false;
      }
      String _string = realValue.toString();
      String _lowerCase = _string.toLowerCase();
      String _string_1 = expectedValue.toString();
      String _lowerCase_1 = _string_1.toLowerCase();
      boolean _contains = _lowerCase.contains(_lowerCase_1);
      _xblockexpression = (_contains);
    }
    return _xblockexpression;
  }
}
